const path = require('path');
// 获取目录,获取文件夹
console.log(path.dirname("D:/myworkspace/base-learn/node/path.js")); // D:/myworkspace/base-learn/node
console.log(path.dirname("D:/myworkspace/base-learn/node")); // D:/myworkspace/base-learn


// / 拿到最后一级的文件名||文件夹 fs.js
let file = path.basename('E:/nodework/node_jichu/node/fs.js')
console.log(file);
// 最后的文件名node
file = path.basename('E:/nodework/node_jichu/node')
console.log(file);
// 拿到文件的后缀名 .html#12
let ext = path.extname('E:/nodework/node_jichu/node/fs.jpg.html#12')
console.log(ext);
// 可以直接是文件名 .js
ext = path.extname('fs.js')
console.log(ext);

// 获取文件名
console.log(path.basename("/tmp/demo/js/test.js", ".js")); // 输出：test
console.log(path.extname("D:/myworkspace/base-learn/node/path.js")); // .js
// 获取扩展名的时候需要注意下面的特殊情况
console.log(path.extname("index.html")); // returns '.html'
console.log(path.extname("index.coffee.md")); // returns '.md'
console.log(path.extname("index.")); // returns '.'
console.log(path.extname("index")); // returns ''
console.log(path.extname(".index")); // returns ''

console.log(path.sep); // 当前是windows系统，返回的是\。如果是linux上是/

// '/'  './' 这两个字符在path.join()的方法中是不起作用的，不加也是一样的效果，只有 '../ ' 才有返回上级目录的作用
console.log(path.join(__dirname,'../'));
console.log(path.join(__dirname,'../a'));
console.log(path.join(__dirname,'../a','b'));
console.log(path.join(__dirname,'c','b','../a'));

console.log(path.join("/foo", "bar", "baz/asdf", "quux", "..")); // \foo\bar\baz\asdf
console.log(path.join("/foo", "bar", "baz/asdf", "quux", "..", "..")); // \foo\bar\baz
console.log(path.join("/foo", "bar", "baz/asdf", "/quux")); // \foo\bar\baz\asdf\quux
console.log(path.join("/foo", "bar", "baz/asdf/", "/quux")); // \foo\bar\baz\asdf\quux
console.log(path.join("/foo", "bar", "baz/asdf", "quux", ".")); // \foo\bar\baz\asdf\quux

console.log('---------resolve--------------');
// 路径为空时，得到结果是当前文件所在的绝对路径，类似 __dirname 
console.log(path.resolve());
// ./ 都不影响路径的拼接；
console.log(path.resolve('a'));
console.log(path.resolve('c','b','a'));
console.log(path.resolve("./","demo","img"));
console.log(path.resolve(__dirname,"demo","img"));
// 以 / 开头跳转到E盘的根路径；
console.log(path.resolve('/a'));
console.log(path.resolve(__dirname,'/a','b','c'));
console.log(path.resolve('a','/b','c'));
console.log(path.resolve('c','b','/a'));
// ../开头，也就是上一层的意思

console.log(path.resolve('../'));
console.log(path.resolve('../a'));
console.log(path.resolve('../a','b'));
console.log(path.resolve('a','../b'));
console.log(path.resolve('c','b','../a'));
console.log(path.resolve('../c','b','a'));